package top.lc951.myglide;

import java.util.concurrent.atomic.AtomicBoolean;

import top.lc951.myglide.util.Util;

public class HardwareConfigState {

    private static volatile HardwareConfigState instance;

    /**
     * Only mutated on the main thread. Read by any number of background threads concurrently.
     *
     * <p>Defaults to {@code false} because we need to wait for the GL context to be initialized and
     * it defaults to not initialized (https://b.corp.google.com/issues/126573603#comment12).
     */
    private final AtomicBoolean isHardwareConfigAllowedByAppState = new AtomicBoolean(false);

    public static HardwareConfigState getInstance() {
        if (instance == null) {
            synchronized (HardwareConfigState.class) {
                if (instance == null) {
                    instance = new HardwareConfigState();
                }
            }
        }
        return instance;
    }

    public void unblockHardwareBitmaps() {
        Util.assertMainThread();
        isHardwareConfigAllowedByAppState.set(true);
    }
}
